<template>
  <div class="box">
    <el-button type="primary" class="btn" style="margin-bottom: 20px;" size="mini" @click="handleAdd"
      v-hasPermi="['pet:ebbasic:add']">新增店铺</el-button>
    <el-table v-loading="loading" :data="ebbasicList" class="grey">
      <el-table-column label="店铺logo" prop="storeLogo">
        <template slot-scope="scope">
          <img :src="scope.row.storeLogo" style="width: 50px;height: 50px;" alt="">
        </template>
      </el-table-column>
      <el-table-column label="店铺图片" prop="storePic">
        <template slot-scope="scope">
          <img :src="scope.row.storePic" style="width: 50px;height: 50px;" alt="">
        </template>
      </el-table-column>
      <el-table-column label="店铺账号" align="center" prop="storeNo" />
      <el-table-column label="店铺名称" align="center" prop="storeName" />
      <el-table-column label="联系电话" align="center" prop="storeLepPhone" />
      <el-table-column label="地址" align="center" prop="initPlace" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['pet:ebbasic:edit']">编辑</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['pet:ebbasic:remove']">清空</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listEbbasic, getEbbasic, delEbbasic, addEbbasic, updateEbbasic } from "@/api/pet/ebbasic";

export default {
  name: "Ebbasic",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 店铺信息 表格数据
      ebbasicList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        storeNo: null,
        storeName: null,
        storeRemark: null,
        storeRate: null,
        storeSimpName: null,
        storeLogo: null,
        storeTime: null,
        storeLepName: null,
        storeLepCode: null,
        storeLepPhone: null,
        pwd: null,
        peoNo: null,
        place: null,
        initPlace: null,
        lng: null,
        lat: null,
        createUser: null,
        updateUser: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询店铺信息 列表 */
    getList() {
      this.loading = true;
      listEbbasic(this.queryParams).then(response => {
        this.ebbasicList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        storeNo: null,
        storeName: null,
        storeRemark: null,
        storeRate: null,
        storeSimpName: null,
        storeLogo: null,
        storeTime: null,
        storeLepName: null,
        storeLepCode: null,
        storeLepPhone: null,
        pwd: null,
        peoNo: null,
        place: null,
        initPlace: null,
        remark: null,
        lng: null,
        lat: null,
        createTime: null,
        createUser: null,
        updateTime: null,
        updateUser: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({ path: '/store/addStore', query: {} })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$router.push({ path: '/store/addStore', query: { id: row.id } })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEbbasic(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEbbasic(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认清空店铺信息 编号为"' + ids + '"的数据项？').then(function () {
        return delEbbasic(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pet/ebbasic/export', {
        ...this.queryParams
      }, `ebbasic_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
